﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Text.RegularExpressions;

namespace University.Workshop.Business
{
    public class LogOnBusiness
    {
        //<Suma
        UserDataAccess userData = new UserDataAccess();
        UserLogOn user = UserLogOn.Instance;
     
        public  UserLogOn Authentication(string userName, string password)
        {
           
            if (string.IsNullOrEmpty(userName) ||
                string.IsNullOrEmpty(password))
            {
                throw new BusinessException("Porfavor Ingrese Su Cuenta y/o su Contraseña");
            }
            if (!Regex.IsMatch(userName, @"^[a-zA-Z0-9]+$"))
            {
                throw new BusinessException("Existen Letras invalidas en la Cuenta");
            } 
            if (!Regex.IsMatch(password, @"^[a-zA-Z0-9]+$"))
            {
                throw new BusinessException("Existen Letras Invalidas en la Contraseña");
            }
            user  = userData.GetUserByUserName(userName, password);
            if (user == null)
            {
                throw new BusinessException("La Cuenta y Contraseña son Incorrectas");
            }
            return user;
        }
    }

}
